package com.aaa.sls.service.impl;

import com.aaa.common.entity.TbOrder;
import com.aaa.sls.dao.NewsDao;
import com.aaa.sls.entity.News;
import com.aaa.sls.service.OrderService;
import com.netflix.discovery.converters.Auto;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private NewsDao newsDao;
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public TbOrder selectOne(Integer id) {
        return restTemplate.getForObject("http://OrderService/order/selectOne", TbOrder.class);
    }

    @Override
    @HystrixCommand(fallbackMethod = "queryAllFallBack")
    public Map queryAll() {
        Map map = new HashMap();
        map.put("newsList",this.newsDao.queryAll(null));
        map.put("orderService",restTemplate.getForObject("http://OrderServer/order/queryAll",List.class));
        return map;
    }

    /***
     * queryAll  fallBack方法
     * @return
     */
    public Map queryAllFallBack() {
        Map map=new HashMap();
        map.put("4444","宕机了");
        return map;
    }
}
